<% layout('/layouts/default.html', {title: '考核任务通知表管理', libs: ['validate','fileupload']}){ %>
<div class="main-content">
	<div class="box box-main">
		<div class="box-header with-border">
			<div class="box-tools pull-right">
			</div>
		</div>
		<#form:form id="inputForm" model="${dcSupExamNotice}" action="${ctx}/notice/dcSupExamNotice/save" method="post" class="form-horizontal">
			<div class="box-body">
				<div class="row">

					<div class="col-xs-12">
						<div class="form-group">
							<label class="control-label col-sm-2" title="">
								<span class="required ">*</span> ${text('通知标题')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-10">
								<#form:hidden path="isNewRecord"/>
								<#form:hidden path="id" />
								<#form:hidden path="examId" maxlength="64" class="form-control"/>
								<#form:input path="noticeTitle" class="form-control required"/>
							</div>
						</div>
					</div>


					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('通知类型')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:select path="noticeType" dictType="dc_notice_type" blankOption="true" class="form-control" readonly="true"/>
							</div>
						</div>
					</div>
				</div>
				<div class="row">
					<div class="col-xs-12">
						<div class="form-group">
							<label class="control-label col-sm-2" title="">
								<span class="required ">*</span> ${text('通知内容')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-10">
								<#form:textarea path="noticeContent" rows="4" maxlength="500" class="form-control required"/>
							</div>
						</div>
					</div>
				</div>
				<div class="row">
					<div class="col-xs-12">
						<div class="form-group">
							<label class="control-label col-sm-2" title="">
								<span class="required ">*</span> ${text('报送单位')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-10">
								<#form:textarea path="noticeOrgNames" rows="5" class="form-control required"   placeholder="请选择报送单位" onclick="selectOrg()"/>
								<#form:hidden path="noticeOrgs"/>
							</div>
						</div>
					</div>
				</div>
				<div class="col-xs-12">
					<div class="form-group">
						<label class="control-label col-sm-2" title="">
							<span class="required hide">*</span><i class="fa icon-question hide"></i></label>
						<div class="col-sm-10" id="groupDiv">

							<a onclick="fixGroup()"  class="btn btn-primary btn-sm mr10 mb10" style="background-color:#00B7EE;border-color: #00b7ee" >维护常用组</a>


							<a onclick="importGroup()"  class="btn btn-primary btn-sm mr10 mb10" style="background-color:#00B7EE;border-color: #00b7ee" >导入常用组</a>

						</div>
					</div>
				</div>
				<div class="row">
					<div class="col-xs-12">
						<div class="form-group">
							<label class="control-label col-sm-2" title="">
								<span class="required hide">*</span> ${text('考核年度')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-2">
								<#form:select path="examYear" readonly="true" items="${yearList}" blankOption="true" data-placeholder="请选择" itemLabel="yearLabel" itemValue="yearValue" class="form-control width-120" defaultValue="${currentYear}"/>
							</div>
						</div>
					</div>
				</div>
				<div class="row">
					<div class="col-xs-12">
						<div class="form-group">
							<label class="control-label col-sm-2" title="">
								<span class="required ">*</span> ${text('报送时限')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-2">
								<#form:input path="noticeEndTime" readonly="true" maxlength="20" class="form-control laydate required"
								dataFormat="datetime" data-type="datetime" data-format="yyyy-MM-dd HH:mm"/>
							</div>
						</div>
					</div>
				</div>
				<div class="row">
					<div class="col-xs-12">
						<div class="form-group">
							<label class="control-label col-sm-2">
								<span class="required hide">*</span> ${text('附件上传')}：</label>
							<div class="col-sm-10">
								<#form:fileupload id="uploadFile" bizKey="${dcSupExamNotice.id}" bizType="dcSupExamNotice_file"
									uploadType="all" class="" readonly="false" preview="true" maxUploadNum="5"/>
							</div>
						</div>
					</div>
				</div>
			</div>
			<div class="box-footer">
				<div class="row">
					<div class="col-sm-offset-2 col-sm-10">
							<button type="submit" class="btn btn-sm btn-primary" id="btnSubmit" onclick="confirmFabu()"><i class="fa fa-check"></i> ${text('发 布')}</button>&nbsp;

						<button type="button" class="btn btn-sm btn-default" id="btnCancel" onclick="js.closeCurrentTabPage()"><i class="fa fa-reply-all"></i> ${text('关 闭')}</button>
					</div>
				</div>
			</div>
		</#form:form>
	</div>
</div>
<% } %>
<script>
	var  noticeType = '${dcSupExamNotice.noticeType}'
	if(noticeType=='4' ||noticeType=='5'  ){

		$('#noticeOrgNames').attr("readonly",true)
		$('#noticeOrgNames').removeAttr("onclick")
		$('#groupDiv').css("display","none")
	}
	function confirmFabu(){

		$("#inputForm").validate({
			submitHandler: function(form){
				if(noticeType=='5' && !('${dcSupExamNotice.id!}')){
					js.confirm('确认发布细则补充通知吗,一旦发布不支持二次修改', function(data){
						js.ajaxSubmitForm($(form), function(data){
							js.showMessage(data.message);
							if(data.result == Global.TRUE){
								js.closeCurrentTabPage(function(contentWindow){
									contentWindow.page();
								});
							}
						}, "json");
					});
				}else{
					js.ajaxSubmitForm($(form), function(data){
						js.showMessage(data.message);
						if(data.result == Global.TRUE){
							js.closeCurrentTabPage(function(contentWindow){
								contentWindow.page();
							});
						}
					}, "json");
				}

			}
		});

	}

function selectOrg(){
     layer.open({
		type: 2,
		title: ['选择机构'],
		area: ['850px', '600px'],
		 zIndex :29891015,
		content: "${ctx}/notice/dcSupExamNotice/getSixTeenFiveOrg?ids="+$("#noticeOrgs").val(),
		success:function (layero,index){
			var iframe = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
		//	iframe.child($("#noticeOrgs").val(),$("#noticeOrgNames").val());
		}
	});
}

function fixGroup(){
	js.layer.open({
		type: 2,
		title: ['维护常用组', 'font-size:18px; color:orange;'],
		area: ['800px', '500px'],
		scrollbar: true,
		shadeClose: false,
		content: "${ctx}/exam/dcSupExamSumScoreResult/examGroupList",
		btn1: function (index, layero) {
		},
		end:function () {

		}
	});
}

function importGroup(){
	var radioHtml='';
	$.ajax({
		url: "${ctx}/exam/dcSupExamSumScoreResult/listGroup",
		type: "get",
		cache: false,
		async:false,
		success: function(data){
			$.each(data,function(index,item){
				// log(item)
				radioHtml= radioHtml+'<div class="dbd"><input type="radio" name="groupId" value="'+item.id+'"/><span class="xbd">'+item.groupName+'</span></div> '
			})
			layer.open({
				type: 1
				,title: ['导入常用组', 'font-size:18px; color:orange;'] //不显示标题栏
				,btn: ['确认', '取消']
				,btnAlign: 'c'
				,area: '500px;'
				,moveType: 1 //拖拽模式，0或者1
				,content: radioHtml

				,yes: function(layero){

					$.ajax({
						url: "${ctx}/exam/dcSupExamSumScoreResult/radio",
						type: "post",
						cache: false,
						async:false,
						data: {
							"groupId":$("[name='groupId']").filter(":checked").val()

						},
						success: function(data){
							$("#noticeOrgs").val(data.unitCodes)
							$("#noticeOrgNames").val(data.unitNames)
						}
					});


				}
			});
		}
	});


}

</script>
<style>
	.dbd{
		padding: 10px;
		border-bottom: 1px solid gray;
		border-right: 1px solid gray;
		border-left: 1px solid gray;
		margin: auto 10px;
	}
	.dbd:nth-child(1){
		padding: 10px;
		border-bottom: 1px solid gray;
		border-top: 1px solid gray;
	}

	.xbd{
		margin-left: 10px;
	}
</style>